package com.product.android.ui.activity;


import java.io.File;
import java.io.IOException;
import java.util.UUID;

import com.common.android.ui.widget.DatePopupWindow;
import com.common.android.ui.widget.DatePopupWindow.onDateSetListener;
import com.common.android.utils.DisplayUtil;
import com.common.android.utils.FormatUtils;
import com.common.android.utils.ToastUtils;
import com.common.android.utils.audio.AudioAnimManager;
import com.common.android.utils.audio.AudioAnimManager.onPlayAudioAnimListener;
import com.common.android.utils.download.DownloadModule;
import com.common.android.utils.download.ProgressDownloadManager;
import com.common.android.utils.download.ProgressDownloadManager.onDonwloadListener;
import com.nd.android.u.allcommon.R;
import com.product.android.business.ApplicationVariable;
import com.product.android.business.ProductTypeDef.Product;
import com.product.android.business.config.Configuration;
import com.product.android.ui.widget.AnimImageView;
import com.product.android.utils.FileHelper;
import com.product.android.utils.LogUtils;

import de.greenrobot.event.EventBus;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.DownloadListener;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.PopupWindow.OnDismissListener;
/**
 * 
 * <br>Created 2014-7-10 上午9:57:21
 * @version  
 * @author   mengnan		
 *
 * @see 	 
 */


@SuppressLint("SetJavaScriptEnabled")
public class WebViewActivity extends BaseActivity {

    private final String TAG = "NewWebViewActivity";
    public final static int DIALOG_ID=1;
    public final static int SET_DATE=3;
    private WebView mWebView;
    private boolean webviewCanBack = true;
    private boolean webViewBottomHide = false;
    private boolean webViewRefresh = false;    
    private String needTitle="";
    private Button backapppage;
    private TextView  activitytitle;
    private ProgressBar progressBar;
    private ImageView refresh_page;
    private ImageView homepage;
    private ImageView backpage;
    private ImageView forwardpage;
    private ImageView reloadpage;
    private ViewGroup footViewGroup;
    private LinearLayout homepagely;
    private LinearLayout backpagely;
    private LinearLayout forwardpagely;
    private LinearLayout reloadpagely;
    private String url;
    boolean redesk;
    private boolean hasCookie = false;
    private boolean zoomsupport = true;
    private String mDateString;
    private String[] mArrayDate;
    private static int CURRENT=0;           //用于控制语音播放动画
    private PopupWindow mAnimPop;           //语音播放的动画窗口
    private AnimImageView mAnimImageView;
    private AudioAnimManager mAudioAnimManager;
    private DatePopupWindow mDatePicker;
    Handler handler = new Handler() {
        public void handleMessage(Message msg) {// 定义一个Handler，用于处理下载线程与UI间通讯
            if (!Thread.currentThread().isInterrupted()) {
                switch (msg.what) {
                case 0:
                    progressBar.setVisibility(View.VISIBLE);
                    refresh_page.setVisibility(View.GONE);
                    break;
                case 1:
                    initToolbarImg();
                    progressBar.setVisibility(View.GONE);
                    refresh_page.setVisibility(View.VISIBLE);
                    break;
                case SET_DATE:
                    mWebView.loadUrl("javascript:setMonth('"+mDateString+"')");
                    break;
                }
            }
            super.handleMessage(msg);
        }
    };
    public static String EXTARS_WEBVIEW_URL = "extars_webview_url";
    public static String EXTARS_WEBVIEW_NEED_TITLE = "extars_webview_title";
    public static String EXTARS_WEBVIEW_RETURN = "extars_webview_return";
    public static String EXTARS_WEBVIEW_BOTTOMHIDE="extars_webview_bottomhide";
    public static String EXTARS_WEBVIEW_REFRESH="extars_webview_refresh";
    public static String EXTARS_WEBVIEW_HASCOOKIE="extars_webview_hascookie";
    public static String EXTARS_WEBVIEW_ZOOMSUPPORT="extars_webview_zoomsupport";
    /**是否除了webview之外不显示其它控件*/
    public static String EXTARS_WEBVIEW_WEBONLY="extars_webview_webonly";
    //修复BUG #41563引入以下两个常量
    public static String EXTARS_WEBVIEW_PSPID="extars_webview_pspid";
    public static String UNSUB_PSP="unsub_psp_";
    
    private ProgressDownloadManager mDownloadManager;
    private String mPspId;
    private boolean mIsWebOnly=false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_new_web_view);
        mWebView=(WebView)findViewById(R.id.webview);
        url = getIntent().getExtras().getString(EXTARS_WEBVIEW_URL);
        Bundle bundle=getIntent().getExtras();
        if (bundle!=null){
            if(bundle.containsKey(EXTARS_WEBVIEW_NEED_TITLE)){
                needTitle = bundle.getString(EXTARS_WEBVIEW_NEED_TITLE);
            }
            redesk= bundle.getBoolean(EXTARS_WEBVIEW_RETURN);       
            if(bundle.containsKey(EXTARS_WEBVIEW_BOTTOMHIDE)){
                webViewBottomHide =bundle.getBoolean(EXTARS_WEBVIEW_BOTTOMHIDE);
            }
            if(bundle.containsKey(EXTARS_WEBVIEW_REFRESH)){
                webViewRefresh =bundle.getBoolean(EXTARS_WEBVIEW_REFRESH);
            }
            
            if(bundle.containsKey(EXTARS_WEBVIEW_HASCOOKIE)){
                hasCookie =bundle.getBoolean(EXTARS_WEBVIEW_HASCOOKIE);
            }
            
            if(bundle.containsKey(EXTARS_WEBVIEW_ZOOMSUPPORT)){
                zoomsupport =bundle.getBoolean(EXTARS_WEBVIEW_ZOOMSUPPORT);
            }           
            if(bundle.containsKey(EXTARS_WEBVIEW_PSPID)){
                //获取当前查看的内容的公众号ID
                mPspId =bundle.getString(EXTARS_WEBVIEW_PSPID);
            }
            if(bundle.containsKey(EXTARS_WEBVIEW_WEBONLY)){//除了webview之外，不显示其它控件
                mIsWebOnly=bundle.getBoolean(EXTARS_WEBVIEW_WEBONLY);   
            }
        }
        initComponent();// 执行初始化函数
        activitytitle.setText(needTitle);
        loadurl(mWebView, url);
        mDownloadManager=new ProgressDownloadManager();
        EventBus.getDefault().register(this, String.class);
       /* mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl(url);*/
    }
    /**
     * 
     * <br>Created 2014-7-10 上午10:36:55
     * @author       mengnan
    */
    public void initComponent() {// 初始化
        backapppage=(Button)this.findViewById(R.id.app_header_btn_left);
        activitytitle=(TextView)this.findViewById(R.id.app_text_title);
        progressBar= (ProgressBar)this.findViewById(R.id.head_progressBar); 
        refresh_page= (ImageView)this.findViewById(R.id.refresh_page);          
        
        homepage=(ImageView)this.findViewById(R.id.home_page);
        backpage=(ImageView)this.findViewById(R.id.back_page);
        forwardpage=(ImageView)this.findViewById(R.id.forward_page);
        reloadpage=(ImageView)this.findViewById(R.id.reload_page);
        footViewGroup = (ViewGroup) this.findViewById(R.id.webview_foot);
        homepagely=(LinearLayout)this.findViewById(R.id.home_page_layout);
        backpagely=(LinearLayout)this.findViewById(R.id.back_page_layout);
        forwardpagely=(LinearLayout)this.findViewById(R.id.forward_page_layout);
        reloadpagely=(LinearLayout)this.findViewById(R.id.reload_page_layout);
        refresh_page.setOnClickListener(imgOnClick);
        homepagely.setOnClickListener(imgOnClick);
        backpagely.setOnClickListener(imgOnClick);
        forwardpagely.setOnClickListener(imgOnClick);
        reloadpagely.setOnClickListener(imgOnClick);

        backapppage.setOnClickListener(imgOnClick);
        mWebView = (WebView)findViewById(R.id.webview);
        if (webViewBottomHide) {
            footViewGroup.setVisibility(View.GONE);
        }
        else{
            footViewGroup.setVisibility(View.VISIBLE);
        }
//        if(redesk){
//           backapppage.setText(getString(R.string.return_desk));
//        }else{
//           backapppage.setText(getString(R.string.return_txt));
//        }
        mAudioAnimManager=new AudioAnimManager(this);
       mAudioAnimManager.setOnPlayAudioAnimListener(audioAnimListener);
        initWebViewComponent();
        mWebView.addJavascriptInterface(new JavaScriptInterface(), "android");
        if (mIsWebOnly){
            footViewGroup.setVisibility(View.GONE);
            findViewById(R.id.recent_header).setVisibility(View.GONE);
        }
        
        
        LinearLayout llHeader = (LinearLayout)findViewById(R.id.recent_header);
		if (Product.PRODUCT_91XY == Configuration.PRODUCT) {
			
		    if(llHeader != null){
		    	llHeader.setBackgroundResource(R.drawable.xy_bg_header);
		    }
		    
		    backapppage.setBackgroundResource(R.drawable.xy_btn_header_back_bg);
		    activitytitle.setTextColor(getResources().getColor(R.color.xy_header_title));
        } else {
            if(llHeader != null){
            	llHeader.setBackgroundResource(R.drawable.header_bg);
            }
            backapppage.setBackgroundResource(R.drawable.bt_header_return_bg);  
        }     
           
    }

  
    private onPlayAudioAnimListener audioAnimListener=new onPlayAudioAnimListener() {
        @Override
        public void onPrepare() {
            showAudioAnim();
        }
        
        @Override
        public void onPlayFinish() {
            //播放完毕，隐藏动画窗口
            if (mAnimPop!=null){
                mAnimPop.dismiss();
            }
        }
        
        @Override
        public void onAnimPlaying(final int current) {
            runOnUiThread(new Runnable() {
                public void run() {
                    mAnimImageView.showState(current);      
                }
            });
        }
    };
    
    /**
     * 
     * <br>Created 2014-7-10 上午10:37:40
     * @author       mengnan
    */
    private void showAudioAnim(){
        if (mAnimPop==null){
            View view=LayoutInflater.from(this).inflate(R.layout.pop_audio_anim, null);
            mAnimImageView=(AnimImageView) view.findViewById(R.id.animAudio);
            mAnimImageView.setMyTalk(true);
            int w=DisplayUtil.dip2px(WebViewActivity.this, 100);
            mAnimPop=new PopupWindow(view,w ,w);
            mAnimPop.setOnDismissListener(onAnimDismissListener);
            mAnimPop.setBackgroundDrawable(new BitmapDrawable());
            mAnimPop.setOutsideTouchable(true);
        }
        mAnimImageView.showState(AnimImageView.CURRENT_STOP);
        mAnimPop.showAtLocation(mWebView, Gravity.CENTER, 0, 0);
    }
    
    private OnDismissListener onAnimDismissListener=new OnDismissListener() {
        @Override
        public void onDismiss() {
            //语音播放的窗口被取消，停止播放
            mAudioAnimManager.stopPlay();
        }
    };
    /**
     * 
     * <br>Created 2014-7-10 上午10:38:01
     * @author       mengnan
    */
    public void onBackPressed() {
        if (mAnimPop!=null && mAnimPop.isShowing()){
            mAudioAnimManager.stopPlay();
        }else{
            super.onBackPressed();
        }
    };
    
    /**
     * 
     * <br>Created 2014-7-10 上午10:38:05
     * @author       mengnan
    */
    public void initWebViewComponent(){
        mWebView.getSettings().setJavaScriptEnabled(true);// 可用JS
        mWebView.setScrollBarStyle(0);// 滚动条风格，为0就是不给滚动条留空间，滚动条覆盖在网页上
        mWebView.getSettings().setSupportZoom(zoomsupport);
        mWebView.getSettings().setBuiltInZoomControls(zoomsupport);
        mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        mWebView.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
                handler.sendEmptyMessage(0);
                return super.shouldOverrideUrlLoading(view, url);
            }// 重写点击动作,用webview载入
        });
        mWebView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                // 载入进度改变而触发
                super.onProgressChanged(view, progress);
                if (progress == 100) {
                    handler.sendEmptyMessage(1);// 如果全部载入,隐藏进度对话框
                }
            }
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                if (needTitle != null && needTitle.length() > 0) {
                    activitytitle.setText(needTitle);
                } else {
                    activitytitle.setText(title);
                }
            }
        });
        mWebView.setDownloadListener(new MyWebViewDownLoadListener());
    }

    /**
     * 
     * <br>Created 2014-7-10 上午10:38:27
     * @param view webview
     * @param url url
     * @author       mengnan
    */
    public void loadurl(final WebView view, final String url) {
        new Thread() {
            public void run() {
                handler.sendEmptyMessage(0);
                try {
                    if(hasCookie){
                        setCookie();
                    }

                    view.loadUrl(url);// 载入网页
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
    public void setCookie(){
        CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(mWebView.getContext());
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
//      cookieManager.removeSessionCookie();
        cookieManager.setCookie(url, "Client-Type=mobile");
        cookieSyncManager.sync();
    }
    private OnClickListener imgOnClick = new OnClickListener() {
        @Override
        public void onClick(View v) {
            int id=v.getId();
            if (id== R.id.home_page_layout){
                 int count = -1;
                   while(mWebView.canGoBackOrForward(count)){
                        count--;
                    }
                   mWebView.goBackOrForward(count + 1);               
            }else if (id==R.id.back_page_layout){
                if(mWebView.canGoBack()){
                    mWebView.goBack();
                }
            }else if (id==R.id.forward_page_layout){
                if(mWebView.canGoForward()){
                    mWebView.goForward();
                }
            }else if (id==R.id.app_header_btn_left){
                finish();
            }else if (id==R.id.refresh_page || id==R.id.reload_page_layout){
                reloadurl(mWebView);
            }
        }
    };
    /**
     * 
     * <br>Created 2014-7-10 上午10:38:46
     * @param view view
     * @author       mengnan
    */
    public void reloadurl(final WebView view) {
        new Thread() {
            public void run() {
                handler.sendEmptyMessage(0);
                try {
                    view.reload();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
    
    /**
     * 
     * <br>Created 2014-7-10 上午10:39:17
     * @author       mengnan
    */
    private void initToolbarImg(){
        if(mWebView.canGoBack()){
            backpage.setImageResource(R.drawable.toolbar_back_normal);  
            backpagely.setClickable(true);
        }
        else{
            backpage.setImageResource(R.drawable.toolbar_back_disable);
            backpagely.setClickable(false);
        }
        
        if(mWebView.canGoForward()){
            forwardpage.setImageResource(R.drawable.toolbar_forward_normal);    
            forwardpagely.setClickable(true);
        }else{
            forwardpage.setImageResource(R.drawable.toolbar_forward_disable);   
            forwardpagely.setClickable(false);
        }
    }
    /**
     * 
     * <br>Created 2014-7-10 上午10:41:40
     * @version  NewWebViewActivity
     * @author   mengnan		
     *
     * @see 	 
     */
    
    
    private class MyWebViewDownLoadListener implements DownloadListener {

        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                                    long contentLength) {
            // AGENT:Mozilla/5.0 (Linux; U; Android 2.3.3; zh-cn; HTC Desire S Build/GRI40)
            // AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
            // URL:http://sfsnd.91.com/sharefile-service/ofs/down.php?uid=123109&k=8FA7AC614CF323139C2DD37FC36273CB
            // CONTENT:attachment;
            // filename=androidVoice1377743715855.amr;md5=04de3ea368f12602772373ea94f7efda;sha1=04de3ea368f12602772373ea94f7efda
            // MIMETYPE:audio/amr
             LogUtils.i("tag", "url="+url);  
//           getFile(WebViewActivity.this,url);
             if (!TextUtils.isEmpty(contentDisposition)){
                 String[] content=contentDisposition.split(";");
                 boolean isAudio=false;
                 //判断是否语音文件
                 for (int i=0,len=content.length;i<len;i++){
                     if (content[i].indexOf(".amr")>0){
                         isAudio=true;
                         break;
                     }
                 }
                 if (isAudio){
                    try {
                        File file = FileHelper.getDefaultAudioFile(url);
                        if (file!=null && file.exists()){
                            //文件已下载，直接播放
                            LogUtils.d("debug", "audio already download");
                            mAudioAnimManager.playAudio(file);
                            return;
                         }
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (IllegalArgumentException e) {
                        e.printStackTrace();
                    } catch (IllegalStateException e) {
                        e.printStackTrace();
                    } 
                    //下载语音文件
                    startDownloadAudio(url);
                    return;
                 }
             }
             startDownload(url+"&sid="+ApplicationVariable.INSTANCE.getCurrentUserInfo().getSessionId());
        }
    }
    /**
     * 
     * <br>Created 2014-7-10 上午10:42:02
     * @param url url
     * @author       mengnan
    */
    private void startDownloadAudio(String url){
        //showProgressDialog();
        File file;
        try {
            file = FileHelper.getDefaultAudioFile(url);
            mDownloadManager.startDownload(url, file);
            mDownloadManager.setOnDownloadListener(listener);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    /**
     * field:listener
     * Function: 文件下载监听
    
     * @author   cb
     * @since    Ver 1.2
     * @Date     2013   2013-9-4        下午3:53:32
     */
    private onDonwloadListener listener=new onDonwloadListener() {
        @Override
        public void onProgress(long cur,long total) {
//          //显示进度
//          float mProgressValue=cur*100/(float)total;
//          String progress=new DecimalFormat("#").format(mProgressValue)+"%";
//          try {
//              tvProgress.setText(progress);
//              pbDownload.setProgress((int)mProgressValue);    
//          } catch (Exception e) {
//              ToastUtils.display(WebViewActivity.this, e.getMessage());
//          }
        }
        
        @Override
        public void onFail(int res,String error) {
            //下载失败
//          if (mWindow!=null){
//              mWindow.dismiss();  
//          }
            if (res>0){
                try {
                    ToastUtils.display(res);
                } catch (Exception e) {
                }
            }else{
                ToastUtils.display(error);
            }
            ToastUtils.display(WebViewActivity.this, error);
        }

        @Override
        public void onSuccess(File file) {
//          //下载成功
//          if (mWindow==null || !mWindow.isShowing()){
//              //下载进度提示被取消，不播放语音
//              return;
//          }
//          //取消进度窗口，显示播放语音窗口并播放语音
//          mWindow.dismiss();
            try {
                mAudioAnimManager.playAudio(file);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };
    
    /**
     * 
     * <br>Created 2014-7-10 上午10:42:32
     * @param url url
     * @author       mengnan
    */
    private void   startDownload(String url){
        String localDir=FileHelper.getDownloadFilePath();       
        DownloadModule downloadMdl = new DownloadModule(WebViewActivity.this);
        downloadMdl.setSoftName(getString(R.string.app_download));
        downloadMdl.setDownloadDirPath(localDir);
        downloadMdl.setDownloadFileName(UUID.randomUUID().toString());
        downloadMdl.setIntentClassName(null);
        downloadMdl.setSoftUrl(url);
        downloadMdl.setDownloadIco(Configuration.NOTIFICATION_ICON);
        downloadMdl.setNuseProxy(true);
        downloadMdl.setSoftUid(10001);
        downloadMdl.Start();

    }
    /**
     * eventbus收到消息后在主线程里的处理
     * 修复BUG #41563引入
     * <br>Created 2014-5-19 下午2:20:45
     * @param param param
     * @author       cb
    */
    public void onEventMainThread(String param) {
        if (TextUtils.isEmpty(param)) {
            return;
        }
        if (param.contains(UNSUB_PSP)){
            //参数里带有取消关注的关键字，获取取消关注的pspid
            String pspId=param.replace(UNSUB_PSP, "");
            if (mPspId!=null && pspId!=null && pspId.equals(mPspId)){
                //当前查看内容的公众号已被取消关注
                finish();
            }
        }
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this, String.class);
        //解决离开webviewactivity的时候视频、语音播放不会停止的BUG
        mWebView.loadUrl("file:///android_asset/nonexistent.html");
    }
    /**
     * 
     * <br>Created 2014-7-10 上午10:42:50
     * @version  NewWebViewActivity
     * @author   mengnan		
     *
     * @see 	 
     */
    
    
    final class JavaScriptInterface {
        /**
         * Creates a new instance of JavaScriptInterface.
         * <br>Created 2014-6-24 上午10:37:11
         */
        JavaScriptInterface() {
        }
        // @JavascriptInterface 安全漏洞必须加
        /**
         * 
         * <br>Created 2014-6-24 上午10:37:22
         * @author       mengnan
        */
        @JavascriptInterface  
        public void quitGame() {
            finish();
        }
        /**
         * 
         * <br>Created 2014-6-24 上午10:37:31
         * @param date 服务器端日期
         * @author  mengnan
        */
        @JavascriptInterface  
        public void showDatePicker(String date) {
            android.util.Log.d("debug", "showDatePicker:"+date);
            int year=0;
            int month=0;
            if(null==date){
                LogUtils.e(TAG, "date-->"+date);
            }else{
                mArrayDate=date.split("-") ;
                if (mArrayDate!=null && mArrayDate.length>1 && mArrayDate[0]!=null && mArrayDate[1]!=null){
                    year=FormatUtils.parseInt(mArrayDate[0]);
                    month=FormatUtils.parseInt(mArrayDate[1]);
                }
            }
            if (mDatePicker==null){
                LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                final View dialogView = inflater.inflate(R.layout.datectrlyearmonth, null, false);
                // 创建弹出对话框，设置弹出对话框的背景为圆角
                mDatePicker = new DatePopupWindow(dialogView,
                        android.view.ViewGroup.LayoutParams.MATCH_PARENT,
                        android.view.ViewGroup.LayoutParams.WRAP_CONTENT, false);
                mDatePicker.setOnDateSetListener(dateSetListener);
                mDatePicker.setBackgroundDrawable(new BitmapDrawable());
                mDatePicker.setOutsideTouchable(true);
            }
            if (year==0 || month==0){
                mDatePicker.SetToday();
            }else{
                mDatePicker.SetDateInfo(year, month);           
            }
            mDatePicker.showAtLocation(mWebView, Gravity.CENTER, 0, 0);
        }
        /**
         * 
         * <br>Created 2014-6-24 上午10:37:56
         * @return string 返回值传给js
         * @author       mengnan
        */
        @JavascriptInterface  
        public String getDate() {
            return mDateString;
        }
    }
    
    private onDateSetListener dateSetListener=new onDateSetListener() {
        @Override
        public void onDateSet(int year, int month, int day) {
            mDateString=year+"-"+month;
            mWebView.loadUrl("javascript:setMonth('"+mDateString+"')");
        }
    };
}
